/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AgregarProducto.java
 *
 * Created on 11/01/2009, 01:40:39 PM
 */

package UIDelNegocio;

import LogicaDeNegocio.Main;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Anya
 */
public class AgregarProducto extends javax.swing.JFrame {
public static String name;
public static String tipo;
public static String opc;
    /** Creates new form AgregarProducto */
    public AgregarProducto(String name1, String tipo1, String opc1) {
        name= name1;
        tipo= tipo1;
        opc= opc1;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField18 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField19 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jTextField20 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("WellDressing");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jLabel1.setText("Agregar Producto");

        jLabel2.setText("Codigo:");

        jTextField18.setFont(new java.awt.Font("Tahoma", 0, 10));
        jTextField18.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        jTextField18.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jTextField18.setPreferredSize(new java.awt.Dimension(22, 27));

        jLabel3.setText("Descripcion:");

        jLabel4.setText("RIF del Proveedor");

        jTextField19.setFont(new java.awt.Font("Tahoma", 0, 10));
        jTextField19.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        jTextField19.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jTextField19.setPreferredSize(new java.awt.Dimension(22, 27));

        jLabel9.setText("Subclase:");

        jComboBox3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButton1.setText("Agregar");
        jButton1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jComboBox1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel5.setText("Costo:");

        jTextField20.setFont(new java.awt.Font("Tahoma", 0, 10));
        jTextField20.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        jTextField20.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jTextField20.setPreferredSize(new java.awt.Dimension(22, 27));

        jLabel10.setText("Bf");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel3))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5))))
                        .addGap(49, 49, 49)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jTextField18, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextField19, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBox3, javax.swing.GroupLayout.Alignment.LEADING, 0, 85, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jTextField20, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel10)))))
                .addGap(32, 32, 32))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(315, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(96, 96, 96))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(jLabel10))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jTextField20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(28, 28, 28)
                .addComponent(jButton1)
                .addContainerGap(41, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

            Main control = new Main();

        if(opc.compareTo("")==0)
        {



        /*DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
        Date fechaEnt = null;

        try {
            fechaEnt = format.parse(jLabel2.getText());
        } catch (ParseException ex) {
            Logger.getLogger(AgregarEmpleado.class.getName()).log(Level.SEVERE, null, ex);
        }*/

                    DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
      Date fechaEnt = null;
            Date fechaNac = null;
            try {
                fechaEnt = format.parse("01-01-2007");
                fechaNac = format.parse("01-01-2000");
            } catch (ParseException ex) {
                //java.util.logging.Logger.getLogger(Manejador.class.getName()).log(Level.SEVERE, null, ex);
            }

        //int a = control.guardarProducto(jTextField18.getText(), jTextField19.getText(), jTextField20.getText(), fechaNac/*jDateChooser1.getDate()*/, fechaEnt,(String)jComboBox1.getSelectedItem(), (String)jComboBox2.getSelectedItem(), jTextField14.getText(), Integer.parseInt(jTextField15.getText()), (String)jComboBox4.getSelectedItem(),fechaEnt, jTextField17.getText(), "Tertulia", null);


            Adminis vent= new Adminis(name,tipo);
            this.setVisible(false);
            vent.setVisible(true);
        }
        else
        {
            this.setVisible(false);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        
Main control = new Main();
        List c = control.consultarSubclase();

        Iterator e = c.iterator();
        while (e.hasNext()) {
            String d = (String) e.next();
            jComboBox3.addItem(d);
        //jList1.a.add(d, );
        }

        List cc = control.consultarProveedor();

        Iterator ee = cc.iterator();
        while (ee.hasNext()) {
            String dd = (String) ee.next();
            jComboBox1.addItem(dd);
        //jList1.a.add(d, );
        }
        //tambien se van a cargar desde aqui los comboBox dep, clas, subclas

    }//GEN-LAST:event_formWindowActivated

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        Date fecha=new Date();
Main control = new Main();

        int dias=fecha.getDate();
        int mes=fecha.getMonth() +1 ;
        int ano=fecha.getYear()+1900;
        Date fechaEnt = null;
        DateFormat format = new SimpleDateFormat("dd-MM-yyyy");

            try {
                fechaEnt = format.parse(dias + "-" + mes + "-" + ano);
            } catch (ParseException ex) {
                Logger.getLogger(AgregarProductosDeProveedor.class.getName()).log(Level.SEVERE, null, ex);
            }
        System.out.println(fechaEnt.toString());
        int num = control.guardarProducto(jTextField18.getText(),jTextField19.getText(),fechaEnt,fechaEnt,(String)jComboBox3.getSelectedItem());
        if (num==666){
        JOptionPane.showMessageDialog(this, "Producto ya existente", "WellDressing", JOptionPane.ERROR_MESSAGE);
        }
        else{
            control.guardarProducto_proveedor((String) jComboBox1.getSelectedItem(),jTextField18.getText(),Integer.parseInt(jTextField20.getText()));}
    }//GEN-LAST:event_jButton1MouseClicked

    /**
    * @param args the command line arguments
  
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AgregarProducto().setVisible(true);
            }
        });
    }  */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextField18;
    private javax.swing.JTextField jTextField19;
    private javax.swing.JTextField jTextField20;
    // End of variables declaration//GEN-END:variables

}
